
#include "samplers.fx"

struct VS_IN
{
	uint	vertexId	:	SV_VertexId;
};

struct VS_OUT
{
	float4 position :	SV_POSITION;
	float2 coords	:	COORDS;
};

struct Material
{
	float4	ambient;
	float4	diffuse;
	float4	specular;
	float4	vIsTextured;	// x:diffuse, y:specular, z:normal
};
Texture2D	tex_diffuse;
Texture2D	tex_specular;
Texture2D	tex_normal;

Texture2D	texTerrainHeight;

float4x4	m_World;
float4x4	m_WorldViewProj;

float2		vCoords;

bool		bAdditive;
float		fRange;

VS_OUT	VS(VS_IN vin)
{
	VS_OUT vout;

	float2 pos[4] = { float2(-1,1), float2(1,1), float2(-1,-1), float2(1,-1) };
	float2 coords[4] = { float2(0,0), float2(1,0), float2(0,1), float2(1,1) };

	vout.coords = coords[vin.vertexId];
	vout.position = float4(pos[vin.vertexId], 0, 1);

	return vout;
}

float4	PS(VS_OUT pin) : SV_Target
{
	
	float d = length(vCoords - pin.coords);

	float scale, s = 0.0f;

	if (bAdditive)
		scale = 0.001f;
	else
		scale = -0.001f;
	

	if (d < fRange) {
		float amount = smoothstep(0.0f, fRange, d);
		s = scale * (1.0f - amount);
	}

	return float4(s,s,s,1);
}

RasterizerState rs_Wireframe
{
	CullMode = Back;
	FillMode = Wireframe;
};

BlendState bs_additive
{
	AlphaToCoverageEnable = false;
	BlendEnable[0] = true;
	

	SrcBlend[0] = ONE;
	DestBlend[0] = ONE;
	BlendOp[0] = ADD;

	SrcBlendAlpha[0] = ONE;
	DestBlendAlpha[0] = ZERO;
	BlendOpAlpha[0] = ADD; 
};


DepthStencilState disabled
{
	DepthEnable = false;
	DepthWriteMask = false;
};




technique10 AlienVS
{
	pass P0
	{
		SetVertexShader( CompileShader( vs_4_0,  VS()   ) );
		SetHullShader ( NULL );
		SetDomainShader( NULL );
		SetGeometryShader( NULL);
		SetPixelShader( CompileShader( ps_4_0,   PS()   ) );
		
		SetBlendState(bs_additive, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xffffffff);
		SetRasterizerState(0);
	}
}
